package com.zz.ecommerce.togatherDeclareMgr.common.dao;

import com.zz.ecommerce.common.CommonDao;
import com.zz.ecommerce.togatherDeclareMgr.common.bean.TCargo;
import com.zz.ecommerce.utils.SqlProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by admin on 2016/1/15.
 */
public interface TCargoDao extends CommonDao<TCargo> {

    @SelectProvider(type = SqlProvider.class, method = "getLongSequence")
    @Options(flushCache = true, useCache = false)
    public String getLongSeq(@Param("sequenceName") String sequenceName);

    @SelectProvider(type = SqlProvider.class, method = "getELongSequence")
    @Options(flushCache = true, useCache = false)
    public String getELongSeq(@Param("sequenceName") String sequenceName);

    @Select("SELECT NVL(MAX(TO_NUMBER(A.SERIALNO)) ,0)\n" +
            "  FROM T_CARGO A\n" +
            " WHERE A.CON_INDX = #{conIndx}\n")
    long queryMaxSerialNo(@Param("conIndx") String conIndx);

    @Delete("DELETE FROM T_CARGO T " +
            "WHERE INDX = #{indx} \n")
    boolean deleteCargoInfo(TCargo cargo);

    @Select("SELECT SUM(DECODE(${colName},'',0,${colName})) || ' ' || ${colUnitName} AS TOTAL\n" +
            "  FROM T_CARGO T\n" +
            " WHERE T.CON_INDX = #{conIndx}\n" +
            "   GROUP BY ${colUnitName}\n" +
            "   ORDER BY ${colUnitName} ASC")
    List<String> statTotal(@Param("colName") String colName,
                           @Param("colUnitName") String colUnitName,
                           @Param("conIndx") String conIndx);
}
